package com.xmg.p2p.base.controller;

import com.xmg.p2p.base.interceptor.RequireLogin;
import com.xmg.p2p.base.util.JSONResult;
import com.xmg.p2p.base.util.UserContext;
import com.xmg.p2p.business.domain.RechargeOffline;
import com.xmg.p2p.business.query.RechargeOfflineQueryObject;
import com.xmg.p2p.business.service.IPlatformBankInfoService;
import com.xmg.p2p.business.service.IRechargeOfflineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * lcd  2020/5/26
 * Description:前台线下充值
 */
@Controller
public class RechargeOfflineController {
    @Autowired
    private IPlatformBankInfoService platformBankInfoService;
    @Autowired
    private IRechargeOfflineService rechargeOfflineService;

    //导向到充值页面,显示银行
    @RequireLogin
    @RequestMapping("recharge")
    public String recharge(Model model){
        model.addAttribute("banks",platformBankInfoService.findAll() );
        return "recharge";
    }

    //前台用户进行线下充值,提交线下充值单
    @RequireLogin
    @RequestMapping("recharge_save")
    @ResponseBody
    public JSONResult save(RechargeOffline rechargeOffline){
        rechargeOfflineService.save(rechargeOffline);
        return new JSONResult();
    }

    //分页查询历史充值记录
    @RequestMapping("recharge_list")
    @RequireLogin
    public String list(Model model, @ModelAttribute("qo")RechargeOfflineQueryObject qo){
        qo.setApplierId(UserContext.getLogininfo().getId());
        model.addAttribute("pageResult", rechargeOfflineService.query(qo));
        return "recharge_list";
    }
}
